<template>
  <div class="tabs-wrap">
    <div class="tabs">
      <div class="tag-item" :class="{'active-tab': activeTab === tab.value}" v-for="(tab, index) in tabs" :key="index"
           @click="changeTab(tab)">
        {{ tab.label }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabList',
  props: {
    tabs: {
      type: Array,
      default: () => [],
    },
    current: {
      type: Number,
      default: 1,
    },
  },
  data() {
    return {
      activeTab: 1,
    }
  },
  watch: {
    current(val) {
      this.activeTab = val;
    }
  },
  mounted() {
    this.activeTab = this.current;
  },
  methods: {
    changeTab(tab) {
      this.activeTab = tab.value;
      this.$emit('change', tab.value);
    },
  }
}
</script>

<style lang="less" scoped>
.tabs-wrap {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 99;
  width: 100%;
  margin-bottom: 16px;
  background-color: #FFFFFF;
  border-radius: var(--td-radius-default);
  //padding: 0 calc(var(--td-comp-paddingLR-l) + 2px);

  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tabs {
  display: flex;
  gap: 24px;
  height: 65px;
  flex-shrink: 0;

  .tag-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 400;
    line-height: 22px;
    color: var(--td-font-gray-1);
    cursor: pointer;
  }

  .active-tab {
    position: relative;
    font-weight: 600;

    &:after {
      position: absolute;
      content: '';
      left: 0;
      right: 0;
      bottom: 4px;
      width: 100%;
      height: 7px;
      border-radius: var(--td-radius-round);
      background-color: #FF5C46;
    }
  }
}

</style>
